package pw.canyingisme.plugin.occupation;

import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import pw.canyingisme.plugin.action.ActionManager;
import pw.canyingisme.plugin.config.ConfigLoader;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import pw.canyingisme.plugin.event.onAction;
import pw.canyingisme.plugin.event.onPlaceholderRequest;

public class OccupationEventListener implements Listener {
    @EventHandler
    public void onEntityDeathEvent(EntityDeathEvent event){
        LivingEntity entity= event.getEntity();
        if(entity instanceof Player){
            if(ConfigLoader.hasOccupation(entity.getName())){
                ActionManager.ApplyAction(entity,1,null);
            }else{
            }
        }
    }
    @EventHandler
    public void onMoveEvent(PlayerMoveEvent event){
        LivingEntity entity= event.getPlayer();
            if(ConfigLoader.hasOccupation(entity.getName())){
                ActionManager.ApplyAction(entity,2,null);
        }
    }
    @EventHandler
    public void onJoin(PlayerJoinEvent event){
        OccupationHealth.setPlayerOccupationHealth(event.getPlayer());
    }
    @EventHandler
    public void onDamage(EntityDamageByEntityEvent event){
        if(event.getDamager() instanceof Player){
            ActionManager.ApplyAction(Bukkit.getPlayer(event.getDamager().getName()),3,null);
            //攻击者触发
            if(event.getEntity() instanceof Player){
                ActionManager.ApplyAction(Bukkit.getPlayer(event.getEntity().getName()),6,null);
            }
        }
    }
    @EventHandler
    public void onDamage(EntityDamageEvent event){
        if (event.getEntity() instanceof Player){
            ActionManager.ApplyAction(Bukkit.getPlayer(event.getEntity().getName()),4,null);
            //被攻击者触发
        }
    }
    @EventHandler
    public void onDamage(EntityDamageByBlockEvent event){
        if (event.getEntity() instanceof Player){
            ActionManager.ApplyAction(Bukkit.getPlayer(event.getEntity().getName()),4,null);
            //被攻击者触发
            ActionManager.ApplyAction(Bukkit.getPlayer(event.getEntity().getName()),7,null);
        }
    }
    @EventHandler
    public void Action(onAction event){
        event.getPlayerEntity();
        event.getAction();
    }
    @EventHandler
    public void Request(onPlaceholderRequest event){
        event.getPlayer();
        event.getIdentifier();
    }
}
